#include <QCoreApplication>
#include "dataconversion.h"
#include "sqlreader.h"
#include <QLocale>

using namespace Qt;

void customMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
    Q_UNUSED(context)

    QByteArray localMsg = msg.toLocal8Bit();
    switch (type) {
    case QtDebugMsg:
        fprintf(stdout, "%s\n", localMsg.constData());
        break;
    // 可以添加其他消息类型的处理，如警告、错误等
    default:
        fprintf(stderr, "Unknown message type: %s\n", localMsg.constData());
        break;
    }
}



int main(int argc, char *argv[])
{

    // 将消息处理函数设置为自定义函数
    qInstallMessageHandler(customMessageHandler);

    QCoreApplication a(argc, argv);


    QStringList args = a.arguments();

    if (argc == 2 && args.at(1) == "--help"){

        qDebug() << "将ODMS日志文件txt或者fitsco文件转换成ODAT工具所需日志格式.\n\n "
                    " --help: get help infomation\n\n"
                    "用法1： 将使用ODMS_DT转化出来的txt文件转换成ODAT工具所需日志格式\n"
                    "ODMSConversion [[format] [src] [dest]] [--help]\n\n"
                    "format: format file path\n"
                    "src: format file path\n"
                    "dest: log file path\n"
                    "eg. ODMSConversion C:\\format.xlsx\\ C:\\example.csv\\ C:\\res.dat\n\n"
                    "用法2： 将使用fitsco文件转换成ODAT工具所需日志格式\n"
                    "ODMSConversion [[src] [dest]] [--help]\n\n"
                    "fitsoFile: .fitsco file path\n"
                    "dest: log file path\n"
                    "eg. ODMSConversion C:\\format.xlsx\\ C:\\example.csv\\ C:\\res.dat\n";
    } else {
        if (argc == 3) {
            SqlReader sr;
            sr.readDBFile(args.at(1));
            sr.save(args.at(2));
        }

        if(argc == 4) {
            DataConversion dc;
            dc.readFormatFile(args.at(1));

            dc.conversion(args.at(2));

            dc.save(args.at(3));

        }
        if (argc > 4) {
            qDebug() << "Command format error";
        }

    }

    return a.exit(0);
}
